<?php
/**
 * Created by PhpStorm.
 * User: QK
 * Date: 2018-07-25
 * Time: 下午 4:31
 */
namespace app\blog\controller;
use app\blog\model\CouponModel as cou;
use cmf\controller\AdminBaseController;

class CouponController extends AdminBaseController{
    /**
     * 类别列表页面
    */
    public function _initialize()
    {
        parent::_initialize();
        $this->cou=new cou();
    }
    public function indexs()
    {

    }
    public function index(){
        $param = $this->request->param();
        $rest       = $this->cou->index($param);
        $this->assign('data',$rest);
        $this->assign('page',$rest->render());
        return $this->fetch('coupon/index');
    }
    /**
     * 发送优惠券页面
    */
    public function set(){
        $where['status']=1;
        $coupon=$this->cou->getcone($where);
        $this->assign('coupon',$coupon);
        return $this->fetch('coupon/set');
    }
    /**
     *添加会员操作
    */
    public function user(){
        $date       = $this->request->param();
        $rest       = $this->cou->user($date,1);
        $this->assign('user',$rest);
        $this->assign('page',$rest->render());
        return $this->fetch('coupon/user');

    }
    /*获取会员名字组建成字符串*/
    public function username()
    {
         $user_id=$_POST['date'];
         $user_id=explode(',',$user_id);
         $nick_name=array();
         foreach($user_id as $k=>$v)
         {
             if($v)
             {
                 $where['id']=$v;
                 $name=$this->cou->user($where,2);
                 $nick_name[$k]=$name['nick_name'];
             }
         }
         $nick_name=implode(',',$nick_name);
         $this->success($nick_name);
    }
    /*发送优惠券*/
    public function add()
    {
        $array=$this->request->param();
        $stataus=$this->cou->add($array);
        if($stataus>0)
        {
             $this->success('发放成功',"coupon/index");
        }else{
            $this->error('发放失败');
        }

    }
}